package com.helloworld.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.helloworld.pojo.Supplier;

@Repository
public class SupplierDao extends HibernateDaoSupport{
	@Autowired  
    public void setSessionFactoryOverride(SessionFactory sessionFactory)  
    {  
        super.setSessionFactory(sessionFactory);  
    } 
	
	/**
	 * 供应商档案查询
	 * @param criteria
	 * @return
	 */
	public List<Supplier> findSupplierByPage(DetachedCriteria criteria,int firstResult,int maxResults){
		return (List<Supplier>) super.getHibernateTemplate().findByCriteria(criteria,firstResult, maxResults);
	}
	
	/**
	 * 查询供应商档案总记录数
	 * @return
	 */
	public List<Long> findCount(String hql) {
        return (List<Long>) super.getHibernateTemplate().find(hql);//返回的是List<?>
    }
	
	/**
	 * 添加供应商
	 * @param supplier
	 */
	@Transactional
	public void addSupplier(Supplier supplier) {
		super.getHibernateTemplate().save(supplier);
		supplier.getSupplierId();
	}
}
